#include<iostream>
#include<cmath>
using namespace std;
const int N = 1e3 + 10;
typedef struct
{
	int chinese;
	int math;
	int english;
	int sum;
}score;
score s[N];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i].chinese;
		cin >> s[i].math;
		cin >> s[i].english;
		s[i].sum = s[i].chinese + s[i].english + s[i].math;
	}
	int count = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j && abs(s[i].sum - s[j].sum) <= 10 && abs(s[i].chinese - s[j].chinese)<=5
				&& abs(s[i].math - s[j].math)<=5 && abs(s[i].english - s[j].english)<=5) {
				count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}


